var chatTable;
function getChatList() {
	if (typeof chatTable !== 'undefined') {
		chatTable.fnPageChange('first');
		return;
	}
	var i = 1;
	chatTable = $("#chatList")
			.DataTable(
					{
						"sAjaxSource" : _path + "/chatData/queryByPage",
						"fnServerParams" : function(aoData) {
							aoData.push(
									{"name" : "liveId","value" : $("#liveId").val()},
									{"name" : "chatType","value" : $("#chatType").val()},
									{"name" : "cahtRobotId","value" : $("#cahtRobotId").val()},
									{"name" : "chatContent","value" : $("#chatContent").val()},
									{ "name": "fromDate", "value": $("#fromDate").val() },
						            { "name": "toDate", "value": $("#toDate").val() }
							);
						},
						"sServerMethod" : "POST",
						"sAjaxDataProp" : "dataList",
						"fnCreatedRow" : function() {
							i++;
						},
						"fnPreDrawCallback" : function() {
							i = 1;
						},
						"aoColumns" : [
								{
									"sTitle" : "序号",
									"sWidth" : "2%",
									"mData" : function() {
										return i;
									}
								},
								/*
								{
									"sTitle" : "直播ID",
									"mData" : "liveId",
									"sWidth" : "2%"
								},
								{
									"sTitle" : "直播名称",
									"mData" : "live.name",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "播放状态",
									"mData" : "live.status",
									"sWidth" : "2%",
										"mRender" : function(data) {
											var status = '';
											switch (data) {
											case '0':
												status = '片花';
												break;
											case '1':
												status = '直播';
												break;
											case '2':
												status = '回放';
												break;
											}
											return status;
										}
								},*/
								{
									"sTitle" : "用户昵称",
									"mData" : "userNickName",
									"sWidth" : "6%"
								},
								{
									"sTitle" : "内容类别",
									"mData" : "chatType",
									"sWidth" : "2%",
									"mRender" : function(data) {
										var chatType = '';
										switch (data) {
										case '1':
											chatType = '文字';
											break;
										case '2':
											chatType = '图片';
											break;
										case '3':
											chatType = '红包';
											break;
										case '4':
											chatType = '打赏';
											break;
										}
										return chatType;
									}
								},
								{
									"sTitle" : "内容",
									"mData" : "chatContent",
									"sWidth" : "20%",
									"mRender": function (data) {
										var chatContent='';
										if(data.indexOf('/upload/confPic')==0){
											chatContent = '<a href="'+data+'" target="_blank"><img style="height:60px;width:40px" src="'+data+'"/></a>';
										}else{
											chatContent = data;
										}
										return chatContent;
									}
								},
								{
									"sTitle" : "发布时间",
									"mData" : "createTime",
									"sWidth" : "10%"
								},
								{
									"sTitle" : "是否已经生成",
									"mData" : "isok",
									"sWidth" : "2%",
									"mRender" : function(data) {
										var chatType = '';
										switch (data) {
										case '0':
											chatType = '没有';
											break;
										case '1':
											chatType = '已生成';
											break;
										}
										return chatType;
									}
								}
								/*,
								{
									"sTitle" : "操作",
									"sWidth" : "10%",
									"mData" : function(data) {
													
										var	status = '&nbsp;<a href="javascript:inquiry('
													+ data.id
													+ ');"  class="btn default btn-xs red"><i class="fa fa-trash-o" title="删除"></i></a>';
								
										return status;
									}
								} */
								]
					});
}





function inquiry(id) {

	layer.confirm('您确定要删除吗？', {
		btn : [ '确定', '取消' ]
	// 按钮
	}, function() {
		layer.closeAll('dialog');
		$.ajax({
			url : _path + "/chat/del/" + id,
			type : "get",
			dataType : "json",
			async : false,
			error : function(request) {
				alert("连接错误！");
			},
			success : function(data) {
				  if(data.msg=='成功'){
					  layer.close
					  App.bubble(200, "删除成功");
						getChatList();
				  }else{
					  App.bubble(200, "删除异常");
				  }
			}
		});
	}, function() {

	});
}